
/**
 * Created with IntelliJ IDEA.
 * User: Simon Xiao
 * Date: 12-11-6
 * Time: 下午4:33
 * To change this template use File | Settings | File Templates.
 */
package sample.userinfo

import org.goodsl.mdd.*
import org.goodsl.mdd.annotation.*
import org.goodsl.mdd.validator.Default


class UserInfo extends Box{
    //@TypeSetting("年龄")
    ManAge age
    //@TypeSetting("姓名")
    UserName name
    //@TypeSetting("密码")
    PassWord passWord

    //@TypeSetting("出生日期")
    BirthDay birthDay
    //@TypeSetting("身份证号")
    HumanID id
    //@TypeSetting("家庭住址")
    @Nullable
    Address address
	
    //@TypeSetting("邮箱")
    EmailAddress masterEmail
	
    //@TypeSetting("备用邮箱")
    @Nullable
    EmailAddress secondEmail

    Tel telNumber

    //组合校验
    def validator = {
        [
                comp("如果年龄小于18岁，则‘家庭住址’必须填写") {
                    if(this.age > 18)
                        return true
                    else
                        address.value!=null && address.value.toString().length()>0
                }
        ]

    }
}

@ValueType(int)
class ManAge extends Seg {


    def validator = {
        use(Default) {
            [
                    Min(5),
                    Max(98),
                    Digits()
            ]
        }
    }
}
@ValueType(String)
class UserName extends Seg {
    //
    def validator = {
        use(Default) {
            [

                    Size(5, 8),
                    Pattern("[a-zA-Z]*", "用户名只能为字母")

            ]
        }
    }
}
@ValueType(Date)
class BirthDay extends Seg {
    def validator = {
        use(Default) {
            [
                    Past()

            ]
        }
    }
}

@ValueType(String)
class HumanID extends Seg {
    def validator = {
        use(Default) {
            [
                    Digits()
            ]
        }
    }
}

@ValueType(String)
class NetAddress extends Seg {
    def validator = {
        use(Default) {
            [
                    Url(),
                    AllowNull()
            ]
        }
    }
}

@ValueType(String)
class FtpAddress extends Seg {
    def validator = {
        use(Default) {
            [
                    Url("ftp", "必须是ftp地址")
            ]
        }
    }
}

@ValueType(String)
class EmailAddress extends Seg {
    def validator = {
        use(Default) {
            [
                    Email()
            ]
        }
    }
}

@ValueType(String)
class Tel extends Seg {
    def validator = {
        use(Default) {
            [
                    Digits(),
                    CCC("必须135开头") {
                        this.value.toString().startsWith("135")
                    }
            ]
        }
    }
}

@ValueType(String)
class PassWord extends Seg{
    def validator = {
        use(Default) {
            [
                    NotBlank()
            ]
        }
    }
}

@ValueType(String)
class Address extends Seg{
    def validator = {
        use(Default) {
            [
                    Size(10,100)
            ]
        }
    }
}
